package com.jtcl.log.config;

import com.jtcl.log.controller.CecLogWebController;
import com.jtcl.log.service.IReadLogService;
import com.jtcl.log.service.impl.LogBackReadLogService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "cec.log", name = "enable", havingValue = "true", matchIfMissing = true)
public class CecLogAutoConfiguration {
	
	/** 
	 * <p>Title:授权默认控制器</p>
	 * <p>Description:</p>
	 * @author mqh
	 * @date 2020年3月4日  
	 * @version 1.0 
	 * @return
	 */
	@Bean
	public CecLogWebController cecLogWebController() {
		return new CecLogWebController();
	}
	
	@Bean
	public IReadLogService readLogService() {
		return new LogBackReadLogService();
	}
	
	/*
	 * @Bean public LogWebMvcConfigurer logWebMvcConfigurer() { return new
	 * LogWebMvcConfigurer(); }
	 */
	
	@Bean
	public ServletRegistrationBean<LogViewServlet> logViewServletRegistrationBean() {
		ServletRegistrationBean<LogViewServlet> registrationBean = new ServletRegistrationBean<LogViewServlet>();
		registrationBean.setServlet(new LogViewServlet());
		registrationBean.addUrlMappings("/log/*");
		return registrationBean;
	}
	
}
